var manage = {};
manage.Station = {};
manage.Station.initGrid = function(){
	var options = {};
    var colNames = ["","序号","名称","编号","状态","添加时间"];
    var colModel = [
        {name:"myac",fixed:true,width:80,formatter:"actions",formatoptions:{keys:true}},
        {name:"id",index:"id",width:10,key:true},
        {name:"name",index:"name",width:35,editable:true},
        {name:"code",index:"code",width:25,editable:true},
        {name:"status",index:"status",width:25,editable:true,edittype:"select",editoptions:{value:"正常:正常;关闭:关闭"}},
        {name:"addtime",index:"addtime",width:30,editable:true}
    ];
    options = {colNames:colNames,
               colModel:colModel,
               processUrl:"process.jspx?format=json",
               caption:"工位信息列表"};
    
    customGrid.init(options);
};

manage.Role = {};
manage.Role.initGrid = function(){
	var options = {};
    var colNames = ["","序号","名称","首页地址","添加时间"];
    var colModel = [
        {name:"myac",fixed:true,width:80,formatter:customActions,formatoptions:{keys:true
        	,editformbutton:false,
	        editUrl:"preEdit.jspx?id=",
	        delUrl:"delete.jspx?id="}},
        {name:"id",index:"id",width:10,key:true},
        {name:"name",index:"name",width:35,editable:true},
        {name:"index",index:"index",width:25,editable:true},
        {name:"addtime",index:"addtime",width:30,editable:true}
    ];
    options = {colNames:colNames,
               colModel:colModel,
               newUrl:"preAdd.jspx",
	           editUrl:"preEdit.jspx?id=",
	           delUrl:"del.jspx?id=",
               caption:"角色信息列表"};
    
    customGrid.init(options);
};

manage.Role.init=function(options){
	if(options!==undefined){
		if(options.resourceIds!==undefined){
			var resourceIds = options.resourceIds
			$.each(resourceIds.split(","),function(index,resourceId){
				$(":input[name='resourceIds'][value='"+resourceId+"']").attr("checked",true);
			});
		}
	}
};

manage.Role.getPermission=function(roleid){
	if(roleid>0){
		$.get("getPermission.jspx",{format:"json",id:roleid},function(data){
			if(data!==undefined && data!==null){
				var permissions = data.permissions;
				if(permissions===undefined || permissions===null){
					return;
				}
				$.each(permissions,function(index,permission){
					var resourceid = permission.resourceid;
					$(":input[name='resourceIds'][value='"+resourceid+"']").attr("checked",true);
					var permissionIds = permission.permissionIds;
					if(permissionIds!==undefined && permissionIds!==null){
						$.each(permissionIds.split(","),function(index,permissionId){
							$(":input[name='permission_"+resourceid+"'][value='"+permissionId+"']").attr("checked",true);
						});
					}
					
				});
			}
		});
	}
};

/*---------------------------resource--------------------------------*/
manage.Resource={};
manage.Resource.init=function(){
	manage.Resource.initGrid();
};
manage.Resource.initGrid=function(){
	var options = {}
    ,colNames = ["","序号","名称","上一级","权限标识","有效","添加时间"]
    ,colModel = [
	    {name:"myac",fixed:true,width:80,formatter:customActions,formatoptions:{
	        keys:true,
	        editformbutton:false,
	        editUrl:"preEdit.jspx?id=",
	        delUrl:"delete.jspx?id="}
	    },
	    {name:"id",index:"id",width:10,key:true},
	    {name:"name",index:"name",width:35,editable:true},
	    {name:"parentid",index:"parentid",width:25,editable:true},
	    {name:"permission",index:"permission",width:25},
	    {name:"available",index:"available",width:30},
	    {name:"addtime",index:"addtime",width:25}
	];
	options = {colNames:colNames,
	           colModel:colModel,
	           newUrl:"preAdd.jspx",
	           editUrl:"preEdit.jspx?id=",
	           delUrl:"del.jspx?id=",
	           canEdit:true,
	           canAdd:true,
	           canDel:true,
	           caption:"资源列表"};
	
	customGrid.init(options);
};
manage.Resource.Edit={};
manage.Resource.Edit.init=function(options){
	if(options!==undefined && options.isEdit===true){
		$(":input[name='available'][value='"+options.available+"']").attr("checked",true);
		$("#parentid").val(options.parentid);
	}
};